package com.heyqing.topic.HasCycle_0141;

import java.util.*;

/**
 * ClassName:HasCycle
 * Package:com.heyqing.topic.HasCycle_0141
 * Description:
 *
 * @Date:2024/9/16
 * @Author:Heyqing
 */
public class HasCycle {
    public boolean hasCycle(ListNode head) {
        Set<Integer> set = new HashSet<>();
        while (Objects.nonNull(head)){
            int h = head.hashCode();
            System.out.println(h);
            int prefix = set.size();
            set.add(h);
            if (set.size() == prefix) return true;
            head = head.next;
        }
        return false;
    }
}
